/*
 * @Date: 2020-05-31 17:51:36
 * @LastEditors: 挺哥
 * @LastEditTime: 2020-05-31 20:04:32
 * @FilePath: \myapp\src\pages\home\index(class).js
 */
import React, { Component } from 'react';
import styles from './index.less';
import { Button } from 'antd';
import { connect, history, Link } from 'umi';

@connect(({ home, loading }) => ({
  home,
  loading: loading.models.home,
  updateLoading: loading.effects['home/updateAvatar'],
}))
class Home extends Component {
  constructor(props) {
    super(props);

    this.state = {
      bannerData,
    };
  }

  componentDidMount() {}

  linkList() {
    history.push({
      pathname: '/list',
      query: {
        a: 'b',
      },
    });
  }

  getBannerList = () => {
    this.props.dispatch({
      type: 'home/getBannerList',
      callback: res => {
        console.log(res);
        this.setState({
          bannerData: res.data,
        });
      },
    });
  };

  render() {
    return (
      <div>
        <h1 className={styles.title}>Page index</h1>

        <button onClick={this.linkList}>跳转1</button>
        <Link
          to={{
            pathname: '/list',
            search: '?sort=name',
            hash: '#the-hash',
            state: { fromDashboard: true },
          }}
        >
          跳转2
        </Link>

        {this.state.bannerData && (
          <img src={this.state.bannerData.banner[0].url} alt="" />
        )}

        <Button onClick={this.getBannerList} type="primary">
          发起请求
        </Button>
      </div>
    );
  }
}

export default Home;
